package com.koo.modules.sale.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koo.common.utils.MyStrUtil;
import com.koo.common.utils.PageUtils;
import com.koo.common.utils.Query;
import com.koo.modules.sale.dao.SalePrescriptionOrderContentDao;
import com.koo.modules.sale.entity.SalePrescriptionOrderContentEntity;
import com.koo.modules.sale.service.SalePrescriptionOrderContentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class SalePrescriptionOrderContentServiceImpl extends ServiceImpl<SalePrescriptionOrderContentDao, SalePrescriptionOrderContentEntity> implements SalePrescriptionOrderContentService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        Object key = params.get("key");
        LambdaQueryWrapper<SalePrescriptionOrderContentEntity> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.like(MyStrUtil.isNotEmpty(key), SalePrescriptionOrderContentEntity::getName, key)
//                  .or().eq(MyStrUtil.isNotEmpty(key), SalePrescriptionOrderContentEntity::getCode, key);

        IPage<SalePrescriptionOrderContentEntity> page = this.page(
                new Query<SalePrescriptionOrderContentEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<SalePrescriptionOrderContentEntity> listByStoreId(Long storeId) {
        LambdaQueryWrapper<SalePrescriptionOrderContentEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MyStrUtil.isNotEmpty(storeId), SalePrescriptionOrderContentEntity::getStoreId, storeId);
        return this.list(wrapper);
    }
}